package com.refactor.practice;

import java.math.BigDecimal;
import java.util.Enumeration;
import java.util.Vector;

public class Customer {
	private String _name;
	private Vector _rentals;
	private BigDecimal _totalAmount;
	private int _totalPoints;

	public Customer(String _name, Vector _rentals) {
		this._name = _name;
		this._rentals = _rentals;
	}

	public String getName() {
		return _name;
	}

	public void addRental(Rental arg) {
		_rentals.add(arg);
	}

	public BigDecimal getTotalAmount() {
		return _totalAmount;
	}

	public int getTotalPoints() {
		return _totalPoints;
	}

	public Vector getRentals() {
		return _rentals;
	}

	public String statement() {
		BigDecimal totalAmount = new BigDecimal("0");
		int frequentRenterPoints = 0;
		Enumeration rentals = _rentals.elements();
		String result = "Rental Record for " + getName() + "\n";
		while (rentals.hasMoreElements()) {
			Rental each = (Rental) rentals.nextElement();

			BigDecimal eachTotalPrice = each.getTotalPrice();
			totalAmount = totalAmount.add(eachTotalPrice);

			int points = each.getPoints();
			frequentRenterPoints += points;

			//show figures for this rental
			result += "\t" + each.getMovie().getTitle() +
					"\t" + String.valueOf(eachTotalPrice) + "\n";
		}
		_totalAmount = totalAmount;
		_totalPoints = frequentRenterPoints;

		//add footer lines
		result += "Amount owed is " + String.valueOf(totalAmount) + "\n";
		result += "You earned " + String.valueOf(frequentRenterPoints) +
				" frequent renter points";
		return result;
	}
}
